import { defineStore } from "pinia";
import { getCargoType, getLocation, getPickUp, getWareHouse } from '@/api/modules/dict.js'

const dict = defineStore("dict", {
	state: () => ({
		cargoType: [], // 货物类型
		location: [], // 地址列表
		pickup: [] ,// 自提点列表
		wareHouse: [], // 仓库
	}),
	actions: {
		async getData() {
			const cargoTypeRes = await getCargoType()
			const locationRes = await getLocation()
			const pickupRes = await getPickUp()
			const warehouseRes = await getWareHouse()
			this.cargoType = cargoTypeRes.rows || []
			this.location = locationRes.data || []
			this.pickup = pickupRes.rows || []
			this.wareHouse = warehouseRes.rows || []
		},
		// 检查字典是否为空 
		checkoutIsNull() {
			let check = false
			if(this.cargoType.length <= 0) check = true
			if(this.location.length <= 0) check = true
			if(this.pickup.length <= 0) check = true
			if(this.wareHouse.length <= 0) check = true
			return check
		}
	},
	unistorage: {
		key: "dict", // 缓存的键，默认为该 store 的 id，这里是 main,
		paths: ['cargoType', 'location', 'pickup', 'wareHouse'], // 需要缓存的路径，这里设置 foo 和 nested 下的 data 会被缓存
	}
})

export default dict